package com.holike.crm.util;

import android.os.Build;
import android.view.DisplayCutout;
import android.view.Window;
import android.view.WindowInsets;


public class NotchUtils {

    //判断手机是否为刘海屏手机
    public static boolean isNotchScreen(Window window) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) return false;
        WindowInsets windowInsets = window.getDecorView().getRootWindowInsets();
        if (windowInsets == null) {
            return false;
        }
        return windowInsets.getDisplayCutout() != null;
    }

    //获取刘海高度
    public static int getNotchHeight(Window window) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) return 0;
        WindowInsets windowInsets = window.getDecorView().getRootWindowInsets();
        if (windowInsets == null || windowInsets.getDisplayCutout() == null) {
            return 0;
        }
        return windowInsets.getDisplayCutout().getSafeInsetTop();
    }
}
